﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace Peer.Game.Server
{
    public class PeerConnection
    {

        private readonly HashSet<string> groups = new HashSet<string>();

        private readonly PeerStream peerStream;

        public Guid Guid => peerStream.Id;

        public PeerConnectionManager ConnectionManager { get; set; }

        internal PeerConnection(PeerStream peerStream)
        {
            this.peerStream = peerStream;
        }

        public bool Is(string groupName)
        {
            if (groupName.Contains(","))
            {
                var groupNames = groupName.Split(",");
                return groups.Any(groupNames.Contains);
            }
            return groups.Contains(groupName);
        }

        public PeerConnection AddGroup(string groupName)
        {
            groups.Add(groupName);
            return this;
        }
        public PeerConnection RemoveGroup(string groupName)
        {
            groups.Remove(groupName);
            return this;
        }

    }
}
